package io.github.tangwan.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author tangwan
 * @version V1.0
 * created on 2021/10/8 11:21
 * @since JDK 1.8
 */
public class MyCallable implements Callable<String> {

    @Override
    public String call() throws Exception {
        System.out.println(Thread.currentThread().getName());
        return Thread.currentThread().getName();
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable myCallable = new MyCallable();
        for (int i = 0; i < 10; i++) {
            FutureTask<String> futureTask = new FutureTask<>(myCallable);
            Thread thread = new Thread(futureTask);
            thread.start();
            //阻塞获取
            //System.out.println(futureTask.get());
        }
    }

}
